package com.store;

import java.io.File;

import com.almworks.sqlite4java.SQLiteConnection;
import com.almworks.sqlite4java.SQLiteException;
import com.almworks.sqlite4java.SQLiteStatement;
import com.model.Product;

public class StoreSQLite1 implements DataStore {

	private SQLiteConnection _db;
	private SQLiteStatement _st;
	
	
	@Override
	public void open(String db) {
		_db = new SQLiteConnection(new File(db));
		try {
			_db.open(true);
		} catch (SQLiteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			_st = _db.prepare(DataStore.insertStr);
		} catch (SQLiteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Override
	public void InsertProduct(Product pr)
	{
		try {
			_st.reset();
		} catch (SQLiteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			_st.bind(1, pr.getNume());
		} catch (SQLiteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			_st.bind(2, pr.getPret());
		} catch (SQLiteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			_st.step();
		} catch (SQLiteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Override
	public void close()
	{
		_db.dispose();
	}

}
